var SYNO_WEB = SYNO_WEB || {
    baseHref: $("base").prop("href"),
    baseURI: $("base").prop("href").replace(window.location.protocol + "//" + window.location.host, ""),
    langCode: $("html").data("lang-code"),
    _token: $('input[name="_token"]').val(),
    mainBody: $("#main"),
    lastUrl: location.href
};
!function() {
    var e = new RegExp("^" + SYNO_WEB.baseURI + SYNO_WEB.langCode + "/")
      , t = new RegExp("^/?" + SYNO_WEB.langCode + "/");
    function o() {
        var o = $(this);
        if (1 != o.data("rewrited")) {
            o.data("rewrited", !0);
            var a = o.attr("href");
            void 0 === a || /^http(s)?/.test(a) || /^#/.test(a) || /^javascript/.test(a) || /^mailto:/.test(a) || /^img(.*?)(jpg|png|gif|pdf)/.test(a) || e.test(a) ? /^#(.+)/.test(a) && o.attr("href", location.href.split("#").shift() + a) : t.test(a) ? /^\//.test(a) ? o.attr("href", SYNO_WEB.baseURI + a.substr(1)) : o.attr("href", SYNO_WEB.baseURI + a) : /^\//.test(a) ? o.attr("href", SYNO_WEB.baseURI + SYNO_WEB.langCode + a) : o.attr("href", SYNO_WEB.baseURI + SYNO_WEB.langCode + "/" + a)
        }
    }
    function a(e, t) {
        var o = $.extend({
            speed: 300,
            delay: 0,
            offset: 10,
            includeHeader: !1
        }, t)
          , a = 0;
        if ("top" == e)
            a = 0;
        else if ("number" == typeof e)
            a = e;
        else if (e instanceof jQuery && 1 == e.length)
            a = e.offset().top;
        else {
            if (1 != $(e).length)
                return console.log("SYNO_WEB.scrollTo: element not found"),
                !1;
            a = $(e).offset().top
        }
        $("#menu_link").is(":visible") ? a = a - $("#main_menu").height() - 20 : o.includeHeader ? a -= $("#main_menu").height() : a -= 20,
        a = Math.max(a - o.offset, 0),
        setTimeout((function() {
            console.log("scrollto", a, e),
            $("html, body").stop().animate({
                scrollTop: a
            }, o.speed)
        }
        ), o.delay)
    }
    function n() {
        $(".dotdotdot").each((function() {
            var e = {
                wrap: /^(zh|ja|kr)/.test(SYNO_WEB.langCode) ? "letter" : "word"
            };
            $(this).find(".more") && (e.after = ".more"),
            $(this).dotdotdot(e)
        }
        ))
    }
    function i() {
        console.log("pageLoaded", location.href),
        $("a[href]").each(o),
        location.hash && !/knowledgebase/.test(location.href) && setTimeout((function() {
            var e = decodeURIComponent(location.hash.slice(1))
              , t = $("#" + e + ', [name="' + e + '"]');
            t.length && a(t.first())
        }
        ), 250),
        $(".vue").addClass("ready"),
        SYNO_WEB.initFlexslider(),
        SYNO_WEB.triggerDotdotdot(),
        SYNO_WEB.initAffixBanner(),
        SYNO_WEB.initFeatureItemMenu()
    }
    function s(e) {
        var t = SYNO_WEB.langCode
          , o = $(this).data("youtube-id")
          , a = 0 == $(this).data("autoplay") ? 0 : 1;
        if ("zh-cn" != t && o) {
            e.preventDefault();
            var n = "zh-tw" == t || "zh-hk" == t ? "zh-Hant" : t.substr(0, 2);
            $.magnificPopup.open({
                showCloseBtn: !0,
                enableEscapeKey: !1,
                items: {
                    src: '<div class="dialog video_dialog"><iframe width="100%" height="100%" src="https://www.youtube.com/embed/' + o + "?autoplay=" + a + "&cc_lang_pref=" + n + '&cc_load_policy=1&rel=0" frameborder="0" gesture="media" allow="autoplay; fullscreen"></iframe></div>',
                    type: "inline"
                },
                mainClass: "mfp-fade",
                closeMarkup: '<button title="%title%" type="button" class="mfp-close mfp-video-close">&#215;</button>'
            })
        } else
            $(this).is(".open_popup") && window.open($(this).prop("href"))
    }
    $(document).ready((function() {
        SYNO_WEB.scrollTo = a,
        SYNO_WEB.triggerDotdotdot = n,
        SYNO_WEB.mainBody.on("pageLoaded", i).trigger("pageLoaded").on("mouseenter click", "a", o).on("click", ".youtube_popup", s),
        SYNO_HELPER.on("resize", {
            key: "SYNO_WEB",
            element: "body",
            trigger: !0
        }, (function() {
            var e = window.innerWidth
              , t = "min mobile";
            e >= 480 && (t = "xs mobile"),
            e >= 568 && (t = "sm mobile"),
            e >= 768 && (t = "md mobile"),
            e >= 1024 && (t = "lg desktop"),
            e >= 1280 && (t = "xl desktop"),
            e >= 1440 && (t = "xxl desktop"),
            $("body").removeClass("xs sm md lg xl xxl desktop mobile").addClass(t)
        }
        ))
    }
    ))
}();
